package com.ruoyi.system;

import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;

import static org.mockito.Mockito.*;

public class MockDemo {

    @Test
    public void test1() {

        List<String> mock = mock(List.class);

        mock.add("one");
//        verify(mock).add("one");
        verify(mock, never()).add("two");

//        verifyNoInteractions(mock);

        when(mock.add(any(String.class))).thenAnswer(new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                Method method = invocation.getMethod();
                Object[] arguments = invocation.getArguments();
                Object invocationMock = invocation.getMock();
                String s = "called with arguments: " + Arrays.toString(arguments);
                System.out.println(s);
                return true;
            }
        });

        System.out.println(mock.add("123"));

        System.out.println();
    }

}
